home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / utils / file / logiso.000 / logiso / Utils / RCS / check_one_link,v < prev    next >
Encoding:
Text File  |  1995-03-24  |  2.3 KB  |  112 lines

  1. head    1.2;
  2. access;
  3. symbols
  4.     VER_0_3:1.2
  5.     VER_0_2:1.1;
  6. locks; strict;
  7. comment    @# @;
  8.  
  9.  
  10. 1.2
  11. date    95.03.24.11.43.35;    author coulter;    state Exp;
  12. branches;
  13. next    1.1;
  14.  
  15. 1.1
  16. date    95.02.19.16.08.08;    author coulter;    state Exp;
  17. branches;
  18. next    ;
  19.  
  20.  
  21. desc
  22. @Script to check and fix one link.  Used by check_links.
  23. @
  24.  
  25.  
  26. 1.2
  27. log
  28. @Checkin version for 0.3 distribution.
  29. @
  30. text
  31. @#! /bin/ksh
  32. USAGE='USAGE: check_one_link FILE_PATH MOUNT_PATH MAP_TO_PATH
  33.    Check one link file.  It is only allowed to be a link to below
  34.    MOUNT_PATH if it is a link to the corresponding file and the
  35.    corresponding file is not a link.  Otherwise, replace the 
  36.    link with the mirror link, i.e. replace MOUNT_PATH with MAP_TO_PATH.
  37. '
  38. # (C) Copyright 1995 by Michael Coulter.  All rights reserved.
  39.  
  40. # Set variables
  41.  
  42. # Process parameters
  43.  
  44.    if [ $# -ne 3 ]
  45.    then
  46.       echo "$USAGE" >&2
  47.       echo "Wrong number of arguments." >&2
  48.       exit 1
  49.    fi
  50.    FILE_PATH="$1"; shift
  51.    if [ ! -L "$FILE_PATH" ]
  52.    then
  53.       echo "$USAGE" >&2
  54.       echo "$FILE_PATH is not a link." >&2
  55.       exit 1
  56.    fi
  57.    MOUNT_PATH="$1"; shift
  58.    if [ ! -d "$MOUNT_PATH" ]
  59.    then
  60.       echo "$USAGE" >&2
  61.       echo "$MOUNT_PATH is not a directory." >&2
  62.       exit 1
  63.    fi
  64.    MAP_TO_PATH="$1"; shift
  65.    if [ ! -d "$MAP_TO_PATH" ]
  66.    then
  67.       echo "$USAGE" >&2
  68.       echo "$MAP_TO_PATH is not a directory." >&2
  69.       exit 1
  70.    fi
  71.  
  72.    LINK="$(ls -l "$FILE_PATH" 2> /dev/null | cut -c56-500 | sed -e 's/^.* //')"
  73.    if [ "$LINK" != "${LINK#$MOUNT_PATH}" ]
  74.    then
  75.       if [ "$MAP_TO_PATH" = "/" ]
  76.       then
  77.          USE_MAP_TO=""
  78.       else
  79.          USE_MAP_TO="$MAP_TO_PATH"
  80.       fi
  81.       EQUIV="${USE_MAP_TO}${LINK#$MOUNT_PATH}"
  82.       if [ ! -L "$LINK" -a "$EQUIV" = "$FILE_PATH" ]
  83.       then
  84.          # A link is allowed to point at an equivalent real file
  85.          exit 0
  86.       fi
  87.       if [ "$EQUIV" = "$FILE_PATH" ]
  88.       then
  89.      NEW_LINK="$(ls -l "$LINK" 2> /dev/null | cut -c56-500 \
  90.                    | sed -e 's/^.* //')"
  91.      if [ "$NEW_LINK" != "${NEW_LINK#$MOUNT_PATH}" ]
  92.      then
  93.         NEW_LINK="${USE_MAP_TO}${LINK#$MOUNT_PATH}"
  94.      fi
  95.      EQUIV="$NEW_LINK"
  96.       fi
  97.       # Replace the link with the equivalent mirror 
  98.       echo "check_links: Replace link at $FILE_PATH with $EQUIV"
  99.       replace_link "$FILE_PATH" "$EQUIV"
  100.    fi
  101.    exit 0
  102. @
  103.  
  104.  
  105. 1.1
  106. log
  107. @Initial revision
  108. @
  109. text
  110. @d8 1
  111. @
  112.